package com.imonsoft.sqm.web.business.supplier_quality;


import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.imonsoft.common.exception.SystemException;
import com.imonsoft.common.httpModel.DataGrid;
import com.imonsoft.common.httpModel.Pager;
import com.imonsoft.common.util.AjaxUtil;
import com.imonsoft.common.util.DateUtil;
import com.imonsoft.common.util.JsonUtil;
import com.imonsoft.sqm.service.business.supplier_quality.SupplierDataService;
import com.imonsoft.sqm.vo.business.supplier_quality.SupplierDataVo;

@Controller
@RequestMapping("/business/supplier_quality/supplier_data")
public class SupplierDataControl {

	protected final Log logger = LogFactory.getLog(getClass());

	@Autowired
	private SupplierDataService supplierDataService;

	@RequestMapping("/listTabOneUI.do")
	public void listTabOneUI(ModelMap model) {
		model.put("year", DateUtil.getNowDate().substring(0, 4));
		model.put("month", DateUtil.getNowDate().substring(5, 7));
	}

	@RequestMapping("/listTabTwoUI.do")
	public void listTabTwoUI(ModelMap model) {
		model.put("year", DateUtil.getNowDate().substring(0, 4));
		model.put("month", DateUtil.getNowDate().substring(5, 7));
	}

	@RequestMapping(value = "/ajaxList.do", method = RequestMethod.POST)
	public void ajaxList(HttpServletResponse response, Pager pager, SupplierDataVo vo) {

		DataGrid<SupplierDataVo> dataGrid = new DataGrid<SupplierDataVo>();
		try {
			dataGrid = supplierDataService.getDataGridVoBy(vo, pager);
		} catch (SystemException se) {
			logger.debug(se.getMessage());
		} catch (Exception e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
		AjaxUtil.renderJSON(response, JsonUtil.bean2json(dataGrid));

	}

	@RequestMapping(value = "/ajaxListBytwo.do", method = RequestMethod.POST)
	public void ajaxListBytwo(HttpServletResponse response, Pager pager, SupplierDataVo vo) {

		DataGrid<SupplierDataVo> dataGrid = new DataGrid<SupplierDataVo>();
		try {
			dataGrid = supplierDataService.getDataGridVoByTwo(vo, pager);
		} catch (SystemException se) {
			logger.debug(se.getMessage());
		} catch (Exception e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
		AjaxUtil.renderJSON(response, JsonUtil.bean2json(dataGrid));

	}

	@RequestMapping("/supplierDataUI.do")
	public void supplierDataUI(ModelMap model, SupplierDataVo vo) {

		SupplierDataVo pojo = supplierDataService.getDataGridVoByList(vo);
		model.put("vo", pojo);
	}

	@RequestMapping("/tabUI.do")
	public void tabUI() {
	}
}
